package com.netdisk.demo.service.impl;

import com.netdisk.demo.entity.Folder;
import com.netdisk.demo.dao.FolderDao;
import com.netdisk.demo.service.FolderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * (Folder)表服务实现类
 *
 * @author makejava
 * @since 2020-05-08 20:04:40
 */
@Service("folderService")
public class FolderServiceImpl implements FolderService {
    @Resource
    private FolderDao folderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Folder queryById(Integer id) {
        return this.folderDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Folder> queryAllByLimit(int offset, int limit) {
        return this.folderDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param folder 实例对象
     * @return 实例对象
     */
    @Override
    public Folder insert(Folder folder) {
        this.folderDao.insert(folder);
        return folder;
    }

    /**
     * 修改数据
     *
     * @param folder 实例对象
     * @return 实例对象
     */
    @Override
    public Folder update(Folder folder) {
        this.folderDao.update(folder);
        return this.queryById(folder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.folderDao.deleteById(id) > 0;
    }

    @Override
    public Collection<Folder> queryAll(Folder folder) {
        return this.folderDao.queryAll(folder);
    }
}